export default {
  //判断是否为相同商品
  addcart(context, payload) {
    return new Promise((resolve, reject) => {
      let oldproduct = null;
      for (const item of context.state.cartList) {
        if (item.iid === payload.iid) {
          oldproduct = item;
        }
      }
      if (oldproduct) {
        //数量加1
        context.commit("addcount", oldproduct);
        resolve('数量加1');
      } else {
        // 数量为1，添加新商品
        payload.count = 1;
        context.commit("addToCart", payload);
        resolve('添加新商品');
      }
    });
  },
};
